package makovo.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.util.Map;
import java.io.EOFException;
import org.apache.struts2.interceptor.SessionAware;

import makovo.data.Resources;
import makovo.entities.Address;
import makovo.entities.Applicant.ApplicantStep;

import com.opensymphony.xwork2.ActionSupport;

public class EditUser extends ActionSupport implements SessionAware {
	private static final long serialVersionUID = 1L;

	private Map<String, Object> mSession;
	private String emailUser;
	private String oldPass;
	private String mPass;

	public String getPass() {
		return this.mPass;
	}

	public void setPass(String pass) {
		this.mPass = pass;
	}

	public String getOldPass() {
		return this.oldPass;
	}

	public void setOldPass(String pass) {
		this.oldPass = pass;
	}

	public void validate() {
		if (!oldPass.equals((String) mSession.get("login.pass"))) {
			addActionError("El password no es correcto");
		}
	}
	
	
	public String execute() {
		try {
			if (Resources.changePassword(emailUser, mPass))
				return "SUCCESS";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "ERROR";
	}

	@Override
	public void setSession(Map<String, Object> sessionInfo) {
		this.mSession = sessionInfo;
		emailUser = (String) mSession.get("login.email");
		System.out.println(emailUser);
	}
}
